import uuidv1 from "uuid/v1";
import axios from "@/utils/requestdp";

let zz = {
  watch: {},
  methods: {
    wuxi() {
      this.$store.state.daping.threecom = this;
      this.$store.state.daping.scencetype = "gongre";
      // this.$store.state.daping.scencetype = "nengxiao";
      //初始化数据操作
      this.catchtydata();
      //全局pick事件
      this.initother();

      let each_point = {
        position: [2.0999920339541296, 0.5513147823930789, 5.083303396617935]
      };

      // this.markgaojing(each_point);

      // setTimeout(() => {
      //   this.$root._earth.sceneTree.$refs['cardwarn'].czmObject.positions.map(item => {
      //     // console.log(item);
      //     this.cardnew.push({
      //       uid: uuidv1(),
      //       type: "warncard",
      //       position: [item[0],item[1],item[2]]
      //     });
      //   })

      //   this.$root._earth.sceneTree.$refs['cardxunjian'].czmObject.positions.map(item => {
      //     // console.log(item);
      //     this.cardnew.push({
      //       uid: uuidv1(),
      //       type: "xunjiancard",
      //       position: [item[0],item[1],item[2]]
      //     });
      //   })

      //   this.$root._earth.sceneTree.$refs['reyonghucard'].czmObject.positions.map(item => {
      //     // console.log(item);
      //     this.cardnew.push({
      //       uid: uuidv1(),
      //       type: "reyonghucard",
      //       position: [item[0],item[1],item[2]]
      //     });
      //   })

      // }, 2000);

      this.cardwuxiobj = {}

      this.addxunjian();

      this.addgaojing()
    },

    addgaojing() {
      axios.post('warn/msg/list', {}).then(res => {
        let data = res.rows;
        setTimeout(() => {
          data.map(item => {
            let uuid = uuidv1();
            this.$root._earth.sceneTree.root.children.push({
              ref: uuid,
              czmObject: {
                name: "Pin|cardgaojing|" + item.id,
                xbsjType: "Pin",
                position: this.$root.modelkv[item.pid].position,
                near: 300,
                // show: true,
                scale: 0.3,
                imageUrl: "/configuration/ziyuan/gaojing.png"
              }
            });

            let pin1 = this.$root._earth.sceneTree.$refs[uuid].czmObject;

            setInterval(() => {
              if (pin1.show) {
                pin1.show = false
                
              }else{
                pin1.show = true
        
              }
            }, _.random(10, 200));

            this.cardwuxiobj[item.id] = item
            this.cardwuxiobj[item.id]['position'] = this.$root.modelkv[item.pid].position
            this.cardwuxiobj[item.id]['oid'] = this.$root.modelkv[item.pid].id
          })
        }, 5000);
      });
    },

    addxunjian() {
      // this.earth.interaction.picking.enabled = true;
      //  inspect/inspectingList
      // axios.get('inspect/inspectingList').then(item =>{
      let res = {
        msg: "操作成功",
        code: 200,
        data: [
          {
            inspectId: 646,
            inspectUserId: 122,
            projectId: null,
            inspectUserName: "胡君",
            startPos: "120.378947@31.559573",
            startPosName: "江苏省无锡市惠山区G42(锡澄运河大桥)",
            startTime: "2021-06-24 08:59:03",
            endTime: "2021-06-24 14:42:15",
            endPos: "120.378947@31.559573",
            endPosName: null,
            distance: null,
            pipelineLength: null,
            allPipelineLength: 0.0,
            timeLength: 343,
            coverage: 0.0,
            serialNum: "20210624-xj-00004428",
            tasks: [],
            workFaults: [],
            inspectClocks: [],
            inspectPos: null,
            hasFaults: null,
            params: null
          },
          {
            inspectId: 629,
            inspectUserId: 190,
            projectId: null,
            inspectUserName: "李文伟",
            startPos: "120.423934@31.508543",
            startPosName: "江苏省无锡市惠山区堰联路",
            startTime: "2021-06-23 10:10:07",
            endTime: "2021-06-23 11:04:56",
            endPos: null,
            endPosName: null,
            distance: null,
            pipelineLength: null,
            allPipelineLength: 0.0,
            timeLength: null,
            coverage: null,
            serialNum: "20210623-xj-00004411",
            tasks: [],
            workFaults: [],
            inspectClocks: [],
            inspectPos: null,
            hasFaults: null,
            params: null
          }
        ]
      };

      res.data.map(item => {
        let position = [];
        if (item.endPos != null) {
          position = [
            (item.endPos.split("@")[0] * 1 * Math.PI) / 180.0,
            (item.endPos.split("@")[1] * 1 * Math.PI) / 180.0,
            0
          ];
        } else {
          position = [
            (item.startPos.split("@")[0] * Math.PI) / 180.0,
            (item.startPos.split("@")[1] * Math.PI) / 180.0,
            0
          ];
        }

        let uuid = uuidv1();

        this.$root._earth.sceneTree.root.children.push({
          ref: uuid,
          czmObject: {
            name: "Pin|cardxunjian|" + item.serialNum,
            xbsjType: "Pin",
            position: position,
            near: 300,
            // show: true,
            scale: 0.3,
            imageUrl: "/configuration/ziyuan/xunjianxiaoren.png"
          }
        });

        this.cardwuxiobj[item.serialNum] = item
        this.cardwuxiobj[item.serialNum]['position'] = position

      });

      // console.log(item);
      // });
    }
  }
};

export default zz;
